<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <title>分类管理</title>
     <script type="text/javascript" src="http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/js/jquery-1.8.2.min.js">
    </script>
   
    <link rel="stylesheet" type="text/css" href="http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/hdjs/hdjs.css">
    <link rel="stylesheet" type="text/css" href="http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="http://localhost/NEWCLASS_515151/nubiya/hdphp/Application/Admin/View/Shop/Css/css.css">
    	
    
    <script type="text/javascript" charset="utf-8" src="http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/ueditor1_4_3/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/ueditor1_4_3/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
    
        <script type="text/javascript" src="http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/uploadify/jquery.uploadify.min.js"></script>
		<link href="http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/uploadify/uploadify.css" type="text/css" rel="stylesheet"></link>
    <script>
                        function getSpecAttr(category_id){
                	$.ajax({
                	type:"post",
                	url:"<?php echo U('getTypeAttr');?>",
                	data:{'cid':category_id},
                	dataType:'json',
                	success:function(phpData){
//              		定义规格和属性字符串
                    var attr='';
                    var spec='';
//                  循环json组合字符串
                    $.each(phpData,function(k,v){
                    	if(v.propertytype==0){
                    		attr +='<tr>'+
		                           '<td style="color:red">'+v.propertyname+'</td>'+
		                           '<td>'+
			                       ' <select name="attr['+v.id+']" id="">'+
				                   ' <option value="">'+
				           	       '请选择属性值'+
				                   '</option>';
				            var option='';
				            $.each(v.propertyvalue,function(kk,vv){
				            	option +='<option value="'+vv+'">'+vv+'</option>';
				            	
				            	
				            });
				            attr +=option;
			           	
			                attr +='</select></td></tr>';
                    		
                    	}else{
                    		spec +='<tr><td  style="color:blue">'+v.propertyname+'</td>'+
		                           '<td><select name="spec['+v.id+'][value][]" id="">'+
				                   '<option value="">请选择规格</option>';
				            var option='';
				            $.each(v.propertyvalue,function(kk,vv){
				            	option +='<option value="'+vv+'">'+vv+'</option>';
				            	
				            	
				            });
				            spec +=option;
			           	
			                spec +='</select></td><td>'+
			           	           '附加价格<input type="text" name="spec['+v.id+'][price][]" value="0"/>'+
	                	           ' <a href="javascript:;" class="hd-btn hd-btn-primary add-spec">添加规格</a></td></tr>';
                    		
                    	}
                    });
    							//插入到属性的表格中
    							$('#attr').html(attr);
    							$('#spec').html(spec);


                	}
                });
                	
                }
    	$(function(){
    		var oldCid=<?php echo $oldData['category_id'];?>;
    		var oldAttr='<?php echo $selected['attr'];?>';
    		var oldSpec='<?php echo $selected['spec'];?>';
    		$('#attr').html(oldAttr);
    		$('#spec').html(oldSpec);
    		$('select[name=category_id]').change(function(){

//  			只要一点到相应分类，就将其对应的类型的属性在下面循环出来
                        var cid = $(this).val();
    					if(cid != oldCid){
    						//调用函数，函数在上面
    						
                        getSpecAttr(cid);
    					}



                
                
    		})
    		//               点击添加规格
                $('.add-spec').live('click',function(){
                	var tr=$(this).parents('tr');
                	var cloneTr=tr.clone();
                	cloneTr.find('a').html('删除规格').removeClass('hd-btn-primary').removeClass('add-spec').addClass('hd-btn-danger remove-spec');
//              	插入到当前tr下一行
                	tr.after(cloneTr);
                })
                $('.remove-spec').live('click',function(){
                	$(this).parents('tr').remove();
                })
//              表单提交把规格和属性放到隐藏域
                $('#shopForm').submit(function(){
                	var attr=$('#attr').html();
                	var spec=$('#spec').html();
//              	存到隐藏域
                    var hidden="<input type='hidden' name='selected[attr]' value='"+attr+"'/>";
                    hidden+="<input type='hidden' name='selected[spec]' value='"+spec+"'/>";
                    $(this).append(hidden);
                })
//              让选中规格和属性都有selected属性
               $('select').live('change',function(){
               	$(this).find('option:selected').attr('selected',true).siblings().removeAttr('selected');
               })
    	})
    </script>
     
   

    

</head>
<body>
<div class="wrap">
    <div class="title-header">添加商品</div>
    <form action="" method="post" class="form-inline hd-form" id="shopForm">
    	
        <table  class="hd-table hd-table-list">
            <tr>
                <th class="w100">商品名称</th>
                <td  class="w100">
                    <input type="text" name="gname" class="w200" value="<?php echo $oldData['gname'];?>"/> 
                </td>
                <td>商品名称长度 1 到 20 位</td>
            </tr>
             <tr>
                <th class="w100">商品货号</th>
                <td>
                   <input type="text" name="gnumber" class="w200" value="<?php echo $oldData['gnumber'];?>"/>
                </td>
                <td>
                	商品货号长度 1 到 655535 位
                </td>
            </tr>
            <tr>
                <th class="w100">商品单位</th>
                <td>
                   <input type="text" name="unit" class="w200" value="<?php echo $oldData['unit'];?>"/>
                </td>
                <td>
                	
                </td>
            </tr>
            <tr>
                <th class="w100">市场价</th>
                <td>
                   <input type="text" name="marketprice" class="w200" value="<?php echo $oldData['marketprice'];?>"/>
                </td>
                <td>
                	
                </td>
            </tr>
            <tr>
                <th class="w100">商城价</th>
                <td>
                   <input type="text" name="shopprice" class="w200" value="<?php echo $oldData['shopprice'];?>"/>
                </td>
                <td>
                	
                </td>
            </tr>
            <tr>
                <th class="w100">是否热卖</th>
                <td>
                   <input type="radio" name="is_hot" value="1" checked/>是&nbsp&nbsp&nbsp&nbsp<input type="radio"  name="is_hot" value="0"/>否
                </td>
                <td>
                	
                </td>
            </tr>
            <tr>
                <th class="w100">列表图</th>
                    <?php if($oldData['listpic']){ ?>
	                <td>
	                	<div class="listpic">
		                	<img src="http://localhost/NEWCLASS_515151/nubiya/hdphp/<?php echo $oldData['listpic'];?>" alt="" style="width:100px" />
		                </div>
	                </td>
                <?php }else{ ?>
	                <td>
	
			            <div lab="uploadFile">
				            			<input id="listpic" type="file" multiple="true" name="listpic">
				            			<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
				            			<script type="text/javascript">
				                		$(function() {
				                    		$('#listpic').uploadify({
				                        		'formData': {//POST数据
				                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
				                        },
				                        'fileTypeDesc' : '上传文件',//上传描述
				                        'fileTypeExts' : '*.jpg;*.png',
				                        'swf'      : 'http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/uploadify/uploadify.swf',
				                        'uploader' : '<?php echo U("uploadList");?>',//上传操作方法
				                        'buttonText':'选择文件',
				                        'fileSizeLimit' : '2000KB',
				                        'uploadLimit' : 1,//上传文件数
				                        'width':65,
				                        'height':25,
				                        'successTimeout':10,//等待服务器响应时间
				                        'removeTimeout' : 0.2,//成功显示时间
				                        'onUploadSuccess' : function(file, data, response) {
				                            data=$.parseJSON(data);
				                            var imageUrl = data.image?data.url:'http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/image/default.png';
				                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70'/><a href='javascript:;' style='color: red;' class='del-img'>X</a><input type='hidden' name='pic' value='"+data.path+"'/></li>";
			//	                            js中合成隐藏域，隐藏于中有listpic字段
				                            var input='<input type="hidden" name="listpic" id="" value="'+data.path+'" />'
				                            $("#uploadList ul").prepend(li);
			//	                            将合成的隐藏域加入ul中
				                            $("#uploadList ul").prepend(input);
				                        }
				                    });
				                });
				            </script>
				            <div id="uploadList">
				                <ul>
				 	
				                </ul>
				            </div>
				        </div>
	                </td>
                <?php } ?>
                <td>
                	
                </td>
            </tr>
            <tr>
                <th class="w100">商品图册</th>
                    <?php if($oldData['shoppic']){ ?>
                <td>
                	<div class="listpic">
	                	<img src="http://localhost/NEWCLASS_515151/nubiya/hdphp/<?php echo $oldData['shoppic'];?>" alt="" style="width:100px" />
	                </div>
                </td>
                <?php }else{ ?>
                <td>
                	<div class="shoppic">
	                	<img src="<?php echo $oldData['shoppic'];?>" alt="" />
	                </div>
                    <div lab="uploadFile">
	            			<input id="pic" type="file" multiple="true">
	            			<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
	            			<script type="text/javascript">
	                		$(function() {
	                    		$('#pic').uploadify({
	                        		'formData': {//POST数据
	                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                        },
	                        'fileTypeDesc' : '上传文件',//上传描述
	                        'fileTypeExts' : '*.jpg;*.png',
	                        'swf'      : 'http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/uploadify/uploadify.swf',
	                        'uploader' : '<?php echo U("uploadPic");?>',//上传操作方法
	                        'buttonText':'选择文件',
	                        'fileSizeLimit' : '2000KB',
	                        'uploadLimit' : 1000,//上传文件数
	                        'width':65,
	                        'height':25,
	                        'successTimeout':10,//等待服务器响应时间
	                        'removeTimeout' : 0.2,//成功显示时间
	                        'onUploadSuccess' : function(file, data, response) {
	                            data=$.parseJSON(data);
	                            var imageUrl = data.image?data.url:'http://localhost/NEWCLASS_515151/nubiya/hdphp/Static/image/default.png';
	                            var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70'/><a href='javascript:;' style='color: red;' class='del-img'>X</a><input type='hidden' name='shopPic[]' value='"+data.path+"'/></li>";
	                            var input= '<input type="hidden" name="shoppic" value="'+data.path+'"/>';
	                            $("#picList ul").prepend(li);
	                            $("#picList ul").prepend(input);
	                        }
	                    });
	                });
	            </script>
	            <div id="picList">
	                <ul>
	 
	                </ul>
	               
	            </div>
	        </div> 
                </td>
                <?php } ?>
                <td>
                	
                </td>
            </tr>


            <tr>
                <th class="w100">所属分类</th>
                <td>
                   <select name="category_id" id="">
                   	    <option value="">--请选择分类--</option>
	                   	<?php foreach ($cateData as $k=>$v){?>
		                   <option value="<?php echo $v['id'];?>"     <?php if($v['id']==$oldData['category_id']){ ?>selected<?php } ?>><?php echo $v['_name'];?></option>
		                <?php }?>  
                   </select>
                </td>
                <td>
                	
                </td>
            </tr>
            <tr>
                <th class="w100">所属品牌</th>
                <td>
                   <select name="brand_id" id="">
	                  
	                   <option value="">--请选择品牌--</option>
	                   <?php foreach ($brandData as $k=>$v){?>
	                   	<option value="<?php echo $v['id'];?>" name="brand_id"      <?php if($v['id']==$oldData['brand_id']){ ?>selected<?php } ?>>
	                   		<?php echo $v['bname'];?>
	                   	</option>
	                   <?php }?>
	                  
                   </select>
                </td>
                <td>
                	
                </td>
            </tr>
            <tr>
                <th class="w100">商品属性</th>
                <td>

                </td>
                <td>
                	
                </td>
            </tr>
        </table>
        <table id="attr" class="hd-table hd-table-list">
        	<!--商品属性的字符串插入这个表格中-->

        	
        </table>

        <table class="hd-table hd-table-list">
        	<tr>
                <th class="w100">商品规格</th>
                <td>

                </td>
                <td>
                	
                </td>
            </tr>
        </table>
        <table id="spec"  class="hd-table hd-table-list">
        	<!--商品规格的字符串插入到这个表格中-->

        </table>
        <table  class="hd-table hd-table-list">

            <tr>
                <th class="w100">商品详细</th>
                <td>
                    <script id="editor" type="text/plain" style="width:600px;height:500px;" name="details"
                    ><?php echo $details['details'];?></script>
                    <script>
	        				var ue = UE.getEditor('editor');
	   				 </script>
                </td>
                <td>
                	
                </td>
            </tr>

 
    
        </table>
        <div class="position-bottom">
        	<input type="hidden" name="gid" value="<?php echo $oldData['gid'];?>"/>
        	
            <input type="submit" class="hd-success" value="添加"/>
        </div>
    </form>
</div>
</body>
</html>